package com.eystar.pdc.controller;

import com.eystar.ext.kit.page.PageKit;
import com.eystar.ext.kit.page.PageOrder;
import com.eystar.ext.render.csv.CSVRender;
import com.eystar.ext.route.ControllerBind;
import com.eystar.pdc.aop.auth.AuthAnno;
import com.eystar.pdc.aop.auth.AuthAnno.AuthType;
import com.eystar.pdc.aop.log.LogAnno;
import com.eystar.pdc.aop.log.LogAnno.LogType;
import com.eystar.pdc.model.Log;
import com.jfinal.plugin.activerecord.Page;

/**
 * Log 管理 
 * @author Zhangjian
 *
 */
@ControllerBind(controllerKey="/log", viewPath="/pdc")
@AuthAnno(type = AuthType.Super, res = "log")
public class LogController extends BaseController {

	/**
	 * 列表展示页面
	 * @throws Exception
	 */
	@AuthAnno(auth="look")
	@LogAnno(desc = "查看日志列表", type = LogType.SEARCH)
	public void index() throws Exception{
		render("log_list.html");
	}
	
	/**
	 * 分页查找
	 * @throws Exception
	 */
	public void page() throws Exception{
		PageOrder order = new PageOrder(getParaToInt("page"), getParaToInt("rows"));
		Log log = getModel(Log.class);
		log.put("start_time", getDatePara2Long("start_time"));
		Page<Log> page = Log.dao.paginate(order, log);
		renderJson(PageKit.toJSON(page));
	}
	
	/**
	 * 点击导出按钮
	 * @throws Exception
	 */
	@AuthAnno(auth = "export")
	@LogAnno(desc = "导出日志", type = LogType.EXPORT)
	public void export() throws Exception{
		Log log = getModel(Log.class);
		log.put("start_time", getDatePara2Long("start_time"));
		Page<Log> page = Log.dao.paginate(new PageOrder(), log);
		render(new CSVRender("log.tpl",page.getList()));
	}
	
}